var c = 0

const b = async () => {
  // 这里的c在第一次走到这儿就被保存了
  // await 在这里会执行完成，但是，后面的语句就得等到微任务执行了
  c = c + (await 10);
  console.log("res2=", c); //10
  // c = (await 10) + c
  c = (await 10) + c; //20
  console.log("res3=", c);
};

b()
c++
console.log('res1=',c)  // 1

/**
 * 输出顺序：
 *          async 同步任务
 *          await 微任务
 *          log 同步任务
 *
 *          res1 1
 *          res2 10
 *          res3 20
 */


const getURLParameters = url =>
    (url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce(
        (a, v) => (
            (a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a
        ),
        {}
    );

console.log(getURLParameters('google.com')); // {}
console.log(getURLParameters('http://url.com/page?name=Adam&surname=Smith&name=ckkkk'));


const sleepSync = (ms) => {
    const end = new Date().getTime() + ms;
    while (new Date().getTime() < end) { /* do nothing */ }
}

const printNums = () => {
    console.log(1);
    sleepSync(500);
    console.log(2);
    console.log(3);
};

printNums(); // Logs: 1, 2, 3 (2 and 3 log after 500ms)
